* GENERAL INFO
	* Project: Red/Blue Workshop and Depolarization
 
* DO FILE INFO
	* Cleans the raw endline data (all campuses)
	* Variable construction
	* ssc install avg_effect 
	* ssc install estout
	* net install dm74.pkg

*********************************************************************************************************************


/* SETUP */

			clear
			set more off
			capture cd "~/Dropbox/Projects/Better Angels RCT/10_Analysis/03_Code/Replication/Final"

			use "endline_raw_all.dta"

/* VAR CLEANING */	

			* POLITICAL ENGAGEMENT 

			gen talk_politics=q32
				destring talk_politics, replace
				replace talk_politics = 5-talk_politics
				la def talk_politics 4 "Nearly everyday" 3 "A few times a week" 2 "A few times a month" 1 "Less than monthly"
				la val talk_politics talk_politics
				la var talk_politics "Talk politics"
			
			
			gen follow_politics=q33
				destring follow_politics, replace
				replace follow_politics = 5-follow_politics
				la def follow_politics 4 "Very closely" 3 "Somewhat closely" 2 "Not very closely" 1 "Not at all"
				la val follow_politics follow_politics
				la var follow_politics "Follow politics"

			gen plan_vote=(q34=="1") if q34!=""
				la var plan_vote "Plan to vote 2020"
			
			gen attend_rally=q351_1
				la var attend_rally "Attended rally past yr"
			gen volunteer=q351_2
				la var volunteer "Worked campaign past yr"
			gen donate_money=q351_3
				la var donate_money "Donated money party/campaign past yr"	
			gen member_group=q351_4
				la var member_group "Member political group past yr"
			gen contact_official=q351_5
				la var contact_official "Contacted elected official past yr"
			gen display_poster=q351_6
				la var display_poster "Displayed political support past yr"
			gen express_support=q351_7
				la var express_support "Expressed political support social media past yr"
			gen attend_protest=q351_8
				la var attend_protest "Attended protest past yr"
			gen sign_petition=q351_9
				la var sign_petition "Signed petition past yr"

			foreach x of varlist attend_rally volunteer donate_money member_group contact_official display_poster express_support attend_protest sign_petition {
				destring `x', replace
				la val `x' yes_no
			}
			
			* IDEOLOGICAL SELF-PLACEMENT
			
				gen lib_scale=q42_1
				destring lib_scale, replace
				la def lib_scale 1 "Extremely liberal" 2 "Liberal" 3 "Slightly liberal" 4 "Moderate" 5 "Slightly conservative" 6 "Conservative" 7 "Extremely conservative"		
				la val lib_scale lib_scale
				la var lib_scale "Liberal-Conservative 7pt scale"
				
				gen ideoextreme=abs(lib_scale-4)
				lab var ideoextreme "Extremity of Ideological Self-Placement"

			 * PARTISAN IDENTITY 
			 
			destring q43, gen(partisan)
			lab def partisan 1 "Republican" 2 "Democrat" 3 "Independent" 4 "Other"
			lab val partisan partisan
			lab var partisan "Partisanship"
			
			gen partisan_other=q43_4_text
			
			destring q51, gen(lean)
			lab def lean 1 "Republican" 2 "Democrat"
			lab val lean lean 
			lab var lean "Lean Partisanship"
			
			
			gen republican=(q43=="1") if q43!=""
				la var republican "PartyID Republican"
			
			gen democrat=(q43=="2") if q43!=""
				la var democrat "PartyID Democrat"
			
			gen democrat_lean=democrat
				replace democrat_lean=1 if q51=="1"
				la var democrat_lean "PartyID Lean Democrat"
		

			gen republican_lean=republican
				replace republican_lean=1 if q51=="2"
				la var republican_lean "PartyID Lean Republican"
			
			gen inparty_image=q63_1
				la var inparty_image "PartyID important self-image"
				
			gen inparty_feel=q63_2
				la var inparty_feel "PartyID unimportant self-esteem"
				
			gen inparty_reflection=q63_3
				la var inparty_reflection "PartyID important reflection of self"
				
			gen inparty_sense=q63_4
				la var inparty_sense "PartyID unimportant to self-concept"
			
			foreach x of varlist inparty_image inparty_feel inparty_reflection inparty_sense {
				destring `x', replace
				la val `x' agree_disagree
			}
			
			gen inparty_feel_rec=8-inparty_feel
				la val inparty_feel_rec agree_disagree_rec
				la var inparty_feel_rec "Rec partyID unimportant self-esteem"
			
			gen inparty_sense_rec=8-inparty_sense
				la val inparty_sense_rec agree_disagree_rec
				la var inparty_sense_rec "Rec partyID unimportant to self-concept"
			
			gen inparty_overlap=q173
				destring inparty_overlap, replace
				la var inparty_overlap "PartyID self-group overlap graphic"
			
			gen inparty_we=q72
				destring inparty_we, replace
				replace inparty_we=inparty_we-3
				la var inparty_we "PartyID We-They freq."
				la val inparty_we always_never
				
			gen inparty_we_rec = 5-inparty_we
				la val inparty_we_rec always_never_rec
				la var inparty_we_rec "Rec partyID We-They freq."
				
				
			 * POLICY POSITIONS 
			
			 * IMMIGRATION 
				
			gen policy_imm_view=q142
				destring policy_imm_view, replace
				la def policy_imm_view 1 "Decreased a lot" 2 "Decreased a little" 3 "left the same" 4 "Increased a little" 5 "Increased a lot" 
				la val policy_imm_view policy_imm_view
				la var policy_imm_view "Imm policy view"
				
			gen policy_imm_imp=q143
				destring policy_imm_imp, replace
				la val policy_imm_imp important_unimportant
				la var policy_imm_imp "Imm policy importance"
	
			gen policy_imm_vote=q144
				destring policy_imm_vote, replace
				la val policy_imm_vote yes_no_maybe2
				/*
			*combines maybe with no
			gen policy_imm_vote_yes=(q144=="1") if q144!=""
				la val policy_imm_vote_yes yes_no
			*combines maybe with yes
			gen policy_imm_vote_yes_maybe=(q144=="1" | q144=="2") if q144!=""
				la val policy_imm_vote_yes_maybe yes_no_maybe
				la var policy_imm_vote_yes_maybe "Imm dealbreaker for vote"
			*gen policy_imm_vote_no=(q144=="3") if q144!=""
				*la var policy_imm_vote_no "Imm dealbreaker for vote01"
				*/
			gen policy_imm_inparty=q145
				destring policy_imm_inparty, replace
				la var policy_imm_inparty "Imm inparty /10 agree"
			
			gen policy_imm_outparty=q146
				destring policy_imm_outparty, replace
				la var policy_imm_outparty "Imm outparty /10 agree"
				
			 * HEALTHCARE
			
			gen policy_health_view=q147
				destring policy_health_view, replace
				la val policy_health_view support_oppose
				la var policy_health_view "Health policy view"
			
			gen policy_health_imp=q148
				destring policy_health_imp, replace
				la val policy_health_imp important_unimportant
				la var policy_health_imp "Health policy importance"
			
			gen policy_health_vote=q149
				destring policy_health_vote, replace
				la val policy_health_vote yes_no_maybe2

			gen policy_health_inparty=q150
				destring policy_health_inparty, replace
				la var policy_health_inparty "Health inparty /10 agree"
			
			gen policy_health_outparty=q151
				destring policy_health_outparty, replace
				la var policy_health_outparty "Health outparty /10 agree"
				
				 * ABORTION 
			
			gen policy_abort_view=q152
				destring policy_abort_view, replace
				la def policy_abort_view 1 "Never permit" 2 "Permit when abuse" 3 "Permit more than when just abuse" 4 "Always permit" 
				la val policy_abort_view policy_abort_view
				la var policy_abort_view "Abort policy view"
			
			gen policy_abort_imp=q153
				destring policy_abort_imp, replace
				la val policy_abort_imp important_unimportant
				la var policy_abort_imp "Abort policy importance"

			gen policy_abort_vote=q154
				destring policy_abort_vote, replace
				la val policy_abort_vote yes_no_maybe2

			gen policy_abort_inparty=q155
				destring policy_abort_inparty, replace
				la var policy_abort_inparty "Abort inparty /10 agree"
			
			gen policy_abort_outparty=q156
				destring policy_abort_outparty, replace
				la var policy_abort_outparty "Abort outparty /10 agree"
				
				* DEFICIT
			
			gen policy_deficit_view=q157
				destring policy_deficit_view, replace
				la def policy_deficit_view 1 "Reduce deficit much more imp" 2 "Reduce deficit little more imp" 3 "Both equally imp" 4 "Reduce unemployment little more imp" 5 "Reduce unemployment much more imp"
				la val policy_deficit_view policy_deficit_view
				la var policy_deficit_view "Deficit policy view"
			
			gen policy_deficit_imp=q158
				destring policy_deficit_imp, replace
				la val policy_deficit_imp important_unimportant
				la var policy_deficit_imp "Deficit policy importance"

			gen policy_deficit_vote=q159
				destring policy_deficit_vote, replace
				la val policy_deficit_vote yes_no_maybe2
			
	
			gen policy_deficit_inparty=q160
				destring policy_deficit_inparty, replace
				la var policy_deficit_inparty "Deficit inparty /10 agree"
			
			gen policy_deficit_outparty=q161
				destring policy_deficit_outparty, replace
				la var policy_deficit_outparty "Deficit outparty /10 agree"
				
				* GUNS
			
			gen policy_guns_view=q162
				destring policy_guns_view, replace
				la def policy_guns_view 1 "A lot easier to buy" 2 "A little easier to buy" 3 "Keep rules about same" 4 "Little more difficult to buy" 5 "A lot more difficult to buy" 
				la val policy_guns_view policy_guns_view
				la var policy_guns_view "Guns policy view"
			
			gen policy_guns_imp=q163
				destring policy_guns_imp, replace
				la val policy_guns_imp important_unimportant
				la var policy_guns_imp "Gun policy importance"

			gen policy_guns_vote=q164
				destring policy_guns_vote, replace
				la val policy_guns_vote yes_no_maybe2

			gen policy_guns_inparty=q165
				destring policy_guns_inparty, replace
				la var policy_guns_inparty "Guns inparty /10 agree"
			
			gen policy_guns_outparty=q166
				destring policy_guns_outparty, replace
				la var policy_guns_outparty "Guns outparty /10 agree"
				
			   * PROPENSITY TO MORALIZE 

			gen policy_imm_moral=q138_1
				la var policy_imm_moral "Imm part moral code"
			gen policy_health_moral=q138_2
				la var policy_health_moral "Health part moral code"
			gen policy_abort_moral=q138_3
				la var policy_abort_moral "Abort part moral code"
			gen policy_deficit_moral=q138_5
				la var policy_deficit_moral "Deficit part moral code"
			gen policy_guns_moral=q138_4
				la var policy_guns_moral "Guns part moral code"
			
			foreach x of varlist policy_imm_moral policy_health_moral policy_abort_moral policy_guns_moral policy_deficit_moral {
				destring `x', replace
				la val `x' not_very
			}
						
			* POLITICAL VALUES 
			
			gen inparty_therm=q71_1
				destring inparty_therm, replace
				la var inparty_therm "Inparty thermometer"
				
			gen outparty_therm=q71_2
				destring outparty_therm, replace
				la var outparty_therm "Outparty thermometer"
				
			gen outparty_therm_rev = 100-outparty_therm
				la var outparty_therm_rev "Outparty thermometer (reverse-coded)"
				
				
			gen inparty_for=(q73=="1") if q73!=""
				la var inparty_for "PartyID for inparty"
			gen outparty_against=(q73=="4") if q73!=""
				la var outparty_against "PartyID against outparty"
			
			gen inparty_patriotic=q75_1
				la var inparty_patriotic "Inparty patriotic"
			gen inparty_intelligent=q75_2
				la var inparty_intelligent "Inparty intelligent"
			gen inparty_honest=q75_3
				la var inparty_honest "Inparty honest"
			gen inparty_open=q75_4
				la var inparty_open "Inparty open-minded"
			gen inparty_generous=q75_5
				la var inparty_generous "Inparty generous"
			gen inparty_hypocrite=q75_6
				la var inparty_hypocrite "Inparty hypocritical"
			gen inparty_selfish=q75_7
				la var inparty_selfish "Inparty selfish"
			gen inparty_mean=q75_8
				la var inparty_mean "Inparty mean"
			
			foreach x of varlist inparty_patriotic inparty_intelligent inparty_honest inparty_open inparty_generous inparty_hypocrite inparty_selfish inparty_mean {
				destring `x', replace
				la val `x' applies
			}
			
			foreach x of varlist inparty_hypocrite inparty_selfish inparty_mean {
				gen `x'_rec=4-`x'
				la val `x'_rec applies_rec
			}
			
			la var inparty_hypocrite_rec "Rec inparty hypocritical"
			la var inparty_selfish_rec "Rec inparty selfish"
			la var inparty_mean_rec "Rec inparty mean"
			
			gen inparty_thought = q169_1
				la var inparty_thought "Inparty capacity complex thought" 
			gen inparty_sensations = q169_2
				la var inparty_sensations "Inparty capacity basic sensations"
			gen inparty_love = q169_3
				la var inparty_love "Inparty capacity love & compassion"
			gen inparty_anger = q169_4
				la var inparty_anger "Inparty capacity anger & hatred"
			
			foreach x of varlist inparty_thought inparty_sensations inparty_love inparty_anger {
				destring `x', replace
				la val `x' capable_incapable
			}
			
			gen inparty_trust = q76
				destring inparty_trust, replace
				la val inparty_trust always_never_alt
				la var inparty_trust "Inparty trust to do right for US"
			
			gen outparty_view = q137_1
				destring outparty_view, replace
				la val outparty_view not_well
				la var outparty_view "Outparty view hard to see"
			
			gen outparty_view_rec = 6-outparty_view
				la val outparty_view_rec not_well_rec
				la var outparty_view_rec "Rec outparty view hard to see"
			
			
			gen outparty_perspective = q137_2
				destring outparty_perspective, replace
				la val outparty_perspective not_well
				la var outparty_perspective "Outparty perspective try to see"
			
			
			gen outparty_friends = q77
				la var outparty_friends "Comfort close friends outparty"
			
			gen outparty_neigh = q78
				la var outparty_neigh "Comfort neighbors outparty"
			
			gen outparty_marry = q79
				la var outparty_marry "Comfort friend marry outparty"
			
			foreach x of varlist outparty_friends outparty_neigh outparty_marry {
				destring `x', replace
				la val `x' comfortable_uncomfortable
			}
	
				alpha outparty_friends outparty_neigh outparty_marry, std item detail gen(comfort_index)
					la var comfort_index "Outparty comfort index"

			gen outparty_patriotic=q710_1
				la var outparty_patriotic "Outparty patriotic"
			gen outparty_intelligent=q710_2
				la var outparty_intelligent "Outparty intelligent"
			gen outparty_honest=q710_3
				la var outparty_honest "Outparty honest"
			gen outparty_open=q710_4
				la var outparty_open "Outparty open-minded"
			gen outparty_generous=q710_5
				la var outparty_generous "Outparty generous"
			gen outparty_hypocrite=q710_6
				la var outparty_hypocrite "Outparty hypocritical"
			gen outparty_selfish=q710_7
				la var outparty_selfish "Outparty selfish"
			gen outparty_mean=q710_8
				la var outparty_mean "Outparty mean"
			
			foreach x of varlist outparty_patriotic outparty_intelligent outparty_honest outparty_open outparty_generous outparty_hypocrite outparty_selfish outparty_mean {
				destring `x', replace
				la val `x' applies
			}
			
			foreach x of varlist outparty_hypocrite outparty_selfish outparty_mean {
				gen `x'_rec=4-`x'
				la val `x'_rec applies_rec
			}
			
			la var outparty_hypocrite_rec "Rec outparty hypocritical"
			la var outparty_selfish_rec "Rec outparty selfish"
			la var outparty_mean_rec "Rec outparty mean"
			
			gen outparty_thought = q170_1
				la var outparty_thought "Outparty capacity complex thought" 
			gen outparty_sensations = q170_2
				la var outparty_sensations "Outparty capacity basic sensations"
			gen outparty_love = q170_3
				la var outparty_love "Outparty capacity love & compassion"
			gen outparty_anger = q170_4
				la var outparty_anger "Outparty capacity anger & hatred"
			
			foreach x of varlist outparty_thought outparty_sensations outparty_love outparty_anger {
				destring `x', replace
				la val `x' capable_incapable
			}
			
			gen outparty_trust = q711
				destring outparty_trust, replace
				la val outparty_trust always_never_alt
				la var outparty_trust "Outparty trust to do right for US"
			  
			gen outparty_threat = (q712 == "1") if q712!=""
				la val outparty_threat yes_no
				la var outparty_threat "Outparty threat to US"
			
			
				
			* CANDIDATE VIGNETTE
			
			*GROUP TREATMENT OR CONTROL FOR CANDIDATE EXPERIMENT
			
			gen canexp_treat_endline =. 
				replace canexp_treat_endline=0 if group=="Control"
				replace canexp_treat_endline=1 if group=="Treatment"
				
			* PAIR 1
			
			gen demcan_t_one = q197_1
				destring demcan_t_one, replace
				la def demcan_t_one 1 "Inparty antidem" 5 "Outparty prodem"
				la val demcan_t_one demcan_t_one
				la var demcan_t_one "DemP1 candidate treatment" 
				
			
			gen demcan_c_one = q200_1
				destring demcan_c_one, replace
				la def demcan_c_one 1 "Inparty prodem" 2 "Outparty prodem"
				la val demcan_c_one demcan_c_one
				la var demcan_c_one "DemP1 candidate control"
				
			gen repcan_t_one = q216_1
				destring repcan_t_one, replace
				la def repcan_t_one 1 "Inparty antidem" 5 "Outparty prodem"
				la val repcan_t_one repcan_t_one
				la var repcan_t_one "RepP1 candidate treatment" 
				
			
			gen repcan_c_one = q217_1
				destring repcan_c_one, replace
				la def repcan_c_one 2 "Inparty prodem" 4 "Outparty prodem"
				la val repcan_c_one demcan_c_one
				la var repcan_c_one "RepP1 candidate control"
				
			gen experiment_elect_one = q237
				destring experiment_elect_one, replace
				la val experiment_elect_one experiment_elect
				la var experiment_elect_one "Exp. electionP1 vote / abstain"
				
			* PAIR 2
			
			gen demcan_t_two = q201_1
				destring demcan_t_two, replace
				la def demcan_t_two 1 "Inparty antidem" 2 "Outparty prodem"
				la val demcan_t_two demcan_t_two
				la var demcan_t_two "DemP2 candidate treatment" 	
			
			gen demcan_c_two = q202_1
				destring demcan_c_two, replace
				*Same values as demcan_c_one
				la val demcan_c_two demcan_c_one
				la var demcan_c_two "DemP2 candidate control"
				
			gen repcan_t_two = q218_1
				destring repcan_t_two, replace
				la def repcan_t_two 2 "Inparty antidem" 4 "Outparty prodem"
				la val repcan_t_two repcan_t_two 
				la var repcan_t_two "RepP2 candidate treatment" 
				
			gen repcan_c_two = q219_1
				destring repcan_c_two, replace
				*Same values as repcan_c_one
				la val repcan_c_two repcan_c_one
				la var repcan_c_two "RepP2 candidate control"
				
			gen experiment_elect_two = q239
				destring experiment_elect_two, replace
				la val experiment_elect_two experiment_elect 
				la var experiment_elect_two "Exp. electionP2 vote / abstain"
			
			* PAIR 3
			
			la def demcan_t_three_eight 1 "Inparty antidem" 2 "Outparty prodem"
			la def demcan_c_three_eight 1 "Inparty prodem" 2 "Outparty prodem"
			la def repcan_t_three_eight 2 "Inparty antidem" 5 "Outparty prodem"
			la def repcan_c_three_eight 2 "Inparty prodem" 5 "Outparty prodem"
			
			
			gen demcan_t_three = q203_1
				destring demcan_t_three, replace
				la val demcan_t_three demcan_t_three_eight
				la var demcan_t_three "DemP3 candidate treatment" 	
			
			gen demcan_c_three = q204_1
				destring demcan_c_three, replace
				la val  demcan_c_three demcan_c_three_eight
				la var demcan_c_three "DemP3 candidate control"
				
			gen repcan_t_three = q221_1
				destring repcan_t_three, replace
				la val repcan_t_three repcan_t_three_eight
				la var repcan_t_three "RepP3 candidate treatment" 
					
			gen repcan_c_three = q222_1
				destring repcan_c_three, replace
				la val repcan_c_three repcan_c_three_eight
				la var repcan_c_three "RepP3 candidate control"
				
			gen experiment_elect_three = q240
				destring experiment_elect_three, replace
				la val experiment_elect_three experiment_elect
				la var experiment_elect_three "Exp. electionP3 vote / abstain"
			
			* PAIR 4
			
			gen demcan_t_four = q205_1
				destring demcan_t_four, replace
				la val demcan_t_four demcan_t_three_eight
				la var demcan_t_four "DemP4 candidate treatment" 	
			
			gen demcan_c_four = q206_1
				destring demcan_c_four, replace
				la val  demcan_c_four demcan_c_three_eight
				la var demcan_c_four "DemP4 candidate control"
				
			gen repcan_t_four = q224_1
				destring repcan_t_four, replace
				la val repcan_t_four repcan_t_three_eight
				la var repcan_t_four "RepP4 candidate treatment" 
				
			
			gen repcan_c_four = q223_1
				destring repcan_c_four, replace
				la val repcan_c_four repcan_c_three_eight
				la var repcan_c_four "RepP4 candidate control"
				
			gen experiment_elect_four = q241
				destring experiment_elect_four, replace
				la val experiment_elect_four experiment_elect
				la var experiment_elect_four "Exp. electionP4 vote / abstain"
			
			
			* PAIR 5
			
			gen demcan_t_five = q207_1
				destring demcan_t_five, replace
				la val demcan_t_five demcan_t_three_eight
				la var demcan_t_five "DemP5 candidate treatment" 	
			
			gen demcan_c_five = q208_1
				destring demcan_c_five, replace
				la val  demcan_c_five demcan_c_three_eight
				la var demcan_c_five "DemP5 candidate control"
				
			gen repcan_t_five = q226_1
				destring repcan_t_five, replace
				la val repcan_t_five repcan_t_three_eight
				la var repcan_t_five "RepP5 candidate treatment" 
				
			
			gen repcan_c_five = q225_1
				destring repcan_c_five, replace
				la val repcan_c_five repcan_c_three_eight
				la var repcan_c_five "RepP5 candidate control"
				
			gen experiment_elect_five = q242
				destring experiment_elect_five, replace
				la val experiment_elect_five experiment_elect
				la var experiment_elect_five "Exp. electionP5 vote / abstain"
			
			* PAIR 6
			
			gen demcan_t_six = q209_1
				destring demcan_t_six, replace
				la val demcan_t_six demcan_t_three_eight
				la var demcan_t_six "DemP6 candidate treatment" 	
			
			gen demcan_c_six = q210_1
				destring demcan_c_six, replace
				la val  demcan_c_six demcan_c_three_eight
				la var demcan_c_six "DemP6 candidate control"
				
			gen repcan_t_six = q228_1
				destring repcan_t_six, replace
				la val repcan_t_six repcan_t_three_eight
				la var repcan_t_six "RepP6 candidate treatment" 
					
			gen repcan_c_six = q227_1
				destring repcan_c_six, replace
				la val repcan_c_six repcan_c_three_eight
				la var repcan_c_six "RepP6 candidate control"
				
			gen experiment_elect_six = q243
				destring experiment_elect_six, replace
				la val experiment_elect_six experiment_elect
				la var experiment_elect_six "Exp. electionP6 vote / abstain"
			
			* PAIR 7
			
			gen demcan_t_seven = q211_1
				destring demcan_t_seven, replace
				la val demcan_t_seven demcan_t_three_eight
				la var demcan_t_seven "DemP7 candidate treatment" 	
			
			gen demcan_c_seven = q212_1
				destring demcan_c_seven, replace
				la val  demcan_c_seven demcan_c_three_eight
				la var demcan_c_seven "DemP7 candidate control"
				
			gen repcan_t_seven = q230_1
				destring repcan_t_seven, replace
				la val repcan_t_seven repcan_t_three_eight
				la var repcan_t_seven "RepP7 candidate treatment" 
				
			gen repcan_c_seven = q229_1
				destring repcan_c_seven, replace
				la val repcan_c_seven repcan_c_three_eight
				la var repcan_c_seven "RepP7 candidate control"
				
			gen experiment_elect_seven = q244
				destring experiment_elect_seven, replace
				la val experiment_elect_seven experiment_elect
				la var experiment_elect_seven "Exp. electionP7 vote / abstain"
			
			* PAIR 8
			
			gen demcan_t_eight = q213_1
				destring demcan_t_eight, replace
				la val demcan_t_eight demcan_t_three_eight
				la var demcan_t_eight "DemP8 candidate treatment" 	
			
			gen demcan_c_eight = q214_1
				destring demcan_c_eight, replace
				la val  demcan_c_eight demcan_c_three_eight
				la var demcan_c_eight "DemP8 candidate control"
				
			gen repcan_t_eight = q232_1
				destring repcan_t_eight, replace
				la def repcan_t_eight_only 2 "Inparty antidem" 7 "Outparty prodem"
				la val repcan_t_eight repcan_t_eight_only
				la var repcan_t_eight "RepP8 candidate treatment" 
				
			gen repcan_c_eight = q231_1
				destring repcan_c_eight, replace
				la val repcan_c_eight repcan_c_three_eight
				la var repcan_c_eight "RepP8 candidate control"
				
			gen experiment_elect_eight = q245
				destring experiment_elect_eight, replace
				la val experiment_elect_eight experiment_elect
				la var experiment_elect_eight "Exp. electionP8 vote / abstain"
		
			

			* SUPPORT FOR CIVIL DISCOURSE
			encode q125, gen(sup_cvl_off)
			recode sup_cvl_off (1=3) (2=2)(3=1) (4=0)
			lab def sup_cvl_off 0 "Not important" 1 "Somewhat important" 2 "Important" 3 "Very important" , replace
			lab val sup_cvl_off sup_cvl_off
			lab var sup_cvl_off "Importance of Inoffensive Language"
			
			encode q123, gen(sup_cvl_grp)
			recode sup_cvl_grp (1=0)(2 3=1)
			lab var sup_cvl_grp "Interest in Talking to Outparty"
		
			
				
				* CAPACITY FOR CIVIL DISCOURSE
				
				
			encode q126, gen(cap_cvl_off)
			recode cap_cvl_off (1=3) (2=2)(3=1) (4=0)
			lab var cap_cvl_off "Confident Using  Inoffensive Language"
			
			encode q124, gen(cap_cvl_tlk)
			recode cap_cvl_tlk (1=1)(2=-1)(3=0)
			lab var cap_cvl_tlk "Enjoy Talking to Outparty"

		

				* CROSS PARTY INTERACTIONS
				
			gen outparty_contact = q171
				destring outparty_contact, replace
				replace outparty_contact = outparty_contact-10
				la val outparty_contact frequency
				la var outparty_contact "Outparty freq. interactions"
				
			gen outparty_talk = q174
				destring outparty_talk, replace
				replace outparty_talk = outparty_talk-64
				la val outparty_talk frequency
				la var outparty_talk "Outparty freq. talk politics"
				
			gen inparty_closefriends = q122_1
				destring inparty_closefriends, replace
				la val inparty_closefriends none_all
				la var inparty_closefriends "Close friends inparty"
				
			gen outparty_closefriends = q122_2
				destring outparty_closefriends, replace
				la val outparty_closefriends none_all
				la var outparty_closefriends "Close friends outparty"
				
			gen indep_closefriends = q122_3
				destring indep_closefriends, replace
				la val indep_closefriends none_all
				la var indep_closefriends "Close friends independents"
				
			gen pricon_frnd_diff = outparty_closefriends + indep_closefriends - inparty_closefriends
			la var pricon_frnd_diff "Outgroup Oriented Friend Group"
				
			
			* DEMOGRAPHICS 
			
			gen woman = (q212=="1") if q212!=""
				lab def woman 0 "Male/other" 1 "Female"
				lab val woman woman
				lab var woman "Woman"
			
				split q213, parse(",") gen(q213) destring
			gen white = (q2131 == 1) if q2131!=.
				replace white = 1 if q2132==1
				replace white = 1 if q2133==1
				la var white "White"
			
			gen asian = (q2131 == 5) if q2131!=.
				replace asian = 1 if q2132==5
				replace asian = 1 if q2133==5
				la var asian "Asian"
			
			drop q2131 q2132 q2133
			
			gen citizen = (q131=="1" | q131=="2") if q131!=""
				 la val citizen yes_no
				 la var citizen "Citizenship"
				 
				 drop if citizen==0
				 
			gen empathy_twosides = q136_1
				la var empathy_twosides "Gen empathy see two sides"
			gen empathy_sorry = q136_2
				la var empathy_sorry "Gen empathy don't feel sry"
			gen empathy_listen = q136_3
				la var empathy_listen "Gen empathy don't listen"
			gen empathy_feelings = q136_4
				la var empathy_feelings "Gen empathy concern feelings"
			gen empathy_imagine = q136_5
				la var empathy_imagine "Gen empathy imagine others' shoes"
			
			foreach x of varlist empathy_twosides empathy_sorry empathy_listen empathy_feelings empathy_imagine {
				destring `x', replace
				la val `x' not_well
			}
			
			foreach x of varlist empathy_sorry empathy_listen {
				gen `x'_rec = 6-`x'
				la val `x'_rec not_well_rec
			}
				
			la var empathy_sorry_rec "Rec gen empathy don't feel sry"
			la var empathy_listen_rec "Rec gen empathy don't listen"	

			

		
		* AD HOMINEM

		    
			*Against dems
			
			gen healthcare_liberty_d = .
				destring q249, replace
				replace healthcare_liberty_d = 5 if q249==10
				replace healthcare_liberty_d = 4 if q249==9
				replace healthcare_liberty_d = 3 if q249==7
				replace healthcare_liberty_d = 2 if q249==5
				replace healthcare_liberty_d = 1 if q249==4
				la var healthcare_liberty_d "Uni healthcare undermine liberty"

		    gen mailin_threat_d = . 
				destring q253, replace
				replace mailin_threat_d = 5 if q253==10
				replace mailin_threat_d = 4 if q253==9
				replace mailin_threat_d = 3 if q253==7
				replace mailin_threat_d = 2 if q253==5
				replace mailin_threat_d = 1 if q253==4
				la var mailin_threat_d "Mail in ballot threat democracy"

			gen police_anarch_d = .	
				destring q255, replace  
				replace police_anarch_d = 5 if q255==10
				replace police_anarch_d = 4 if q255==9
				replace police_anarch_d = 3 if q255==7
				replace police_anarch_d = 2 if q255==5
				replace police_anarch_d = 1 if q255==4
				la var police_anarch_d "Defund police anarchists"
				
		    gen covid_lockdown_d = .
				destring q257, replace  
				replace covid_lockdown_d = 5 if q257==10
				replace covid_lockdown_d = 4 if q257==9
				replace covid_lockdown_d = 3 if q257==7
				replace covid_lockdown_d = 2 if q257==5
				replace covid_lockdown_d = 1 if q257==4
				la var covid_lockdown_d "Covid lockdown political"
			
		    gen gunban_cons_d = . 
				destring q263, replace  
				replace gunban_cons_d = 5 if q263==10
				replace gunban_cons_d = 4 if q263==9
				replace gunban_cons_d = 3 if q263==7
				replace gunban_cons_d = 2 if q263==5
				replace gunban_cons_d = 1 if q263==4
				la var gunban_cons_d "Ban assault anticonstitution"
				
			*Against reps
		   
		    gen covid_protest_r = . 
				destring q247, replace
				replace covid_protest_r = 5 if q247==10
				replace covid_protest_r = 4 if q247==9
				replace covid_protest_r = 3 if q247==7
				replace covid_protest_r = 2 if q247==5
				replace covid_protest_r = 1 if q247==4
				la var covid_protest_r "Covid protest haircut over health"
				
		   gen blm_oppose_r = .
				destring q251, replace
				replace blm_oppose_r = 5 if q251==10
				replace blm_oppose_r = 4 if q251==9
				replace blm_oppose_r = 3 if q251==7
				replace blm_oppose_r = 2 if q251==5
				replace blm_oppose_r = 1 if q251==4
				la var blm_oppose_r "BLM oppose racist"
				
		   gen greendeal_gen_r = . 
				destring q259, replace
				replace greendeal_gen_r = 5 if q259==10
				replace greendeal_gen_r = 4 if q259==9
				replace greendeal_gen_r = 3 if q259==7
				replace greendeal_gen_r = 2 if q259==5
				replace greendeal_gen_r = 1 if q259==4
				la var greendeal_gen_r "Green new deal don't care future"
				
		    gen elect_delay_r = .
				destring q261, replace
				replace elect_delay_r = 5 if q261==10
				replace elect_delay_r = 4 if q261==9
				replace elect_delay_r = 3 if q261==7
				replace elect_delay_r = 2 if q261==5
				replace elect_delay_r = 1 if q261==4
				la var elect_delay_r "Election delay antidemocratic"
				
			gen daca_heart_r = .
				destring q265, replace
				replace daca_heart_r = 5 if q265==15
				replace daca_heart_r = 4 if q265==14
				replace daca_heart_r = 3 if q265==13
				replace daca_heart_r = 2 if q265==12
				replace daca_heart_r = 1 if q265==11
				la var daca_heart_r "DACA oppose heartless"
				
			foreach x of varlist covid_protest_r blm_oppose_r greendeal_gen_r elect_delay_r daca_heart_r healthcare_liberty_d mailin_threat_d police_anarch_d covid_lockdown_d gunban_cons_d {
				destring `x', replace
				*la val `x' agree_disagree_ah
			}
	
				
		 la def disagree_agree_ah 1 "Strongly disagree" 2 "Disagree" 3 "Neither agree nor disagree" 4 "Agree" 5 "Strongly agree" 
		 
			foreach x of varlist covid_protest_r blm_oppose_r greendeal_gen_r elect_delay_r daca_heart_r healthcare_liberty_d mailin_threat_d police_anarch_d covid_lockdown_d gunban_cons_d {
			recode `x' (5=1)(4=2)(3=3)(2=4)(1=5)	
			lab val `x' disagree_agree_ah
			}
			
			
		
			* BEHAVIORAL MEASURE
	
			gen donate_depol = q196
				destring donate_depol, replace
				la var donate_depol "Donation to bridge the divide"
				la def donate_depol 1 "20 Amazon" 2 "15 Amazon 5 Bridge the Divide" 3 "10 Bridge the Divide" 4 "5 Amazon 15 Bridge the Divide" 5 "20 bridge the divide"		
				la val donate_depol donate_depol
				
			gen donate_depol_alt=.
				replace donate_depol_alt=0 if donate_depol==1
				replace donate_depol_alt=5 if donate_depol==2
				replace donate_depol_alt=10 if donate_depol==3
				replace donate_depol_alt=15 if donate_depol==4
				replace donate_depol_alt=20 if donate_depol==5
				
				la var donate_depol_alt "Donation to Bridge the Divide (recoded)"
	
			egen idx_donate_depol_alt=std(donate_depol_alt)
				replace idx_donate_depol_alt=-1*(donate_depol_alt)
					la var idx_donate_depol_alt "(Reversed) Donation to Bridge the Divide (recoded)"

/* VAR & INDEX CONSTRUCTION */
					
			* Generate political engagement index
				
				alpha talk_politics plan_vote attend_rally volunteer donate_money member_group contact_official display_poster express_support attend_protest sign_petition, std item detail gen(idx_pol_engage)
					la var idx_pol_engage "Political engagement index"
				
			* Generate ingroup identity salience indexes
			
				alpha inparty_image inparty_feel_rec inparty_reflection inparty_sense_rec inparty_overlap inparty_we_rec, std item detail gen(idx_ingroup_salience)
					la var idx_ingroup_salience "Ingroup identity salience index"
				
			* Generate individual ideological polarization measure 1 (issue constraint)
			
			*% left leaning
			foreach v in policy_imm_view policy_health_view  policy_deficit_view policy_guns_view {
			recode `v' (4 5=1)(1 2 3=0), gen(L_`v')
			}
			recode policy_abort_view (3 4=1)(1 2 =0), gen(L_policy_abort_view)
			egen leftpolicy=rowmean(L_policy*)
			*% right leaning
			foreach v in policy_imm_view policy_health_view  policy_deficit_view policy_guns_view {
			recode `v' (1 2=1)(4 5 3=0), gen(R_`v')
			}
			recode policy_abort_view (1 2=1)(3 4 =0), gen(R_policy_abort_view)
			egen rightpolicy=rowmean(R_policy*)
			* difference (constraint)
			gen ind_ideo_con=abs(leftpolicy-rightpolicy)
			la var ind_ideo_con "Individual ideological constraint index"
			drop L_* R_* leftpolicy rightpolicy  
			
			* Generate individual ideological polarization measure 2 (issue extremity) -- code from Mason (2018) -- footnote to thank
			* extremity
			foreach v in policy_imm_view policy_health_view  policy_deficit_view policy_guns_view {
			recode `v' (5=1)(4=2), gen(ex`v')
			replace ex`v'=(1-((ex`v'-1)/2))
			}
			recode policy_abort_view (1 4=1)(2=3) (3=2), gen(expolicy_abort_view)
			replace expolicy_abort_view=(1-((expolicy_abort_view-1)/2))
			* importance 
			foreach v in policy_imm_ policy_health_ policy_abort_ policy_deficit_ policy_guns_ {
			gen im`v'imp=(`v'imp-1)/3
			}
			* weight extremity by importance
			foreach v in policy_imm_ policy_health_ policy_abort_ policy_deficit_ policy_guns_ {
			gen `v'ext=ex`v'view * im`v'imp
			}
			alpha policy_imm_ext policy_health_ext policy_abort_ext policy_deficit_ext policy_guns_ext, gen(ind_ideo_ext) 
			la var ind_ideo_ext "Individual ideological extremity index"
			
			drop impolicy_* expolicy_*
				
			* Generate perceived mass ideological polarization index
								
				foreach x in imm health abort deficit guns {
					gen policy_`x'_mass_pol = policy_`x'_inparty - policy_`x'_outparty
				}
				
						la var policy_imm_mass_pol "Imm perceived mass polarization"
						la var policy_health_mass_pol "Health perceived mass polarizaiton"
						la var policy_abort_mass_pol "Abort perceived mass polarization"
						la var policy_deficit_mass_pol "Deficit perceived mass polarization"
						la var policy_guns_mass_pol "Guns perceived mass polarization"
				
				alpha *_mass_pol, std item detail gen(idx_mass_ideo_pol)
					la var idx_mass_ideo_pol "Perceived mass ideological polarization index"
				
			* Generate affective polarization index

				* Generate inparty vs. outparty feeling thermometer

					gen therm_diff = inparty_therm - outparty_therm
						la var therm_diff "Thermometer difference"
				
				* Generate inparty vs. outparty trust score
					
					gen trust_diff = inparty_trust - outparty_trust
						la var trust_diff "In-Out trust difference"
					
				alpha therm_diff outparty_against trust_diff outparty_friends outparty_neigh outparty_marry outparty_threat, std item detail gen(idx_affect_pol)
					la var idx_affect_pol "Affective polarization index"
					
				alpha therm_diff trust_diff outparty_friends outparty_neigh outparty_marry outparty_threat, std item detail gen(idx_affect_pol_noneg)
					la var idx_affect_pol_noneg "Affective polarization index (no negative partisanship)"

				alpha therm_diff trust_diff comfort_index outparty_threat, std item detail gen(idx_affect_pol_noneg_comf)
					la var idx_affect_pol_noneg_comf "Affective polarization index (no negative partisanship, outparty comfort index)"
	
				alpha outparty_therm outparty_trust outparty_friends outparty_neigh outparty_marry outparty_threat, std item detail gen(idx_affect_pol_noneg_out)
					la var idx_affect_pol_noneg_out "Affective polarization index (no negative partisanship, outparty animus only)"

			* Generate stereotyping index
			
				* Generate inparty and outparty stereotyping indexes
		
					gen inparty_stereo_pos = inparty_patriotic + inparty_intelligent + inparty_honest + inparty_open + inparty_generous
						la var inparty_stereo_pos "Inparty pos. stereotyping"

					gen inparty_stereo_neg = inparty_hypocrite + inparty_selfish + inparty_mean
						la var inparty_stereo_neg "Inparty neg. stereotyping"
				
					gen inparty_stereo_all = inparty_patriotic + inparty_intelligent + inparty_honest + inparty_open + inparty_generous + inparty_hypocrite_rec + inparty_selfish_rec + inparty_mean_rec
						la var inparty_stereo_all "Inparty stereotyping index"
		
					gen outparty_stereo_pos = outparty_patriotic + outparty_intelligent + outparty_honest + outparty_open + outparty_generous
						la var outparty_stereo_pos "Outparty pos. stereotyping"
					
					gen outparty_stereo_neg = outparty_hypocrite + outparty_selfish + outparty_mean
						la var outparty_stereo_neg "Outparty neg. stereotyping"
				
					gen outparty_stereo_all = outparty_patriotic + outparty_intelligent + outparty_honest + outparty_open + outparty_generous + outparty_hypocrite_rec + outparty_selfish_rec + outparty_mean_rec
						la var outparty_stereo_all "Outparty stereotyping index"

				gen stereo_diff = inparty_stereo_all - outparty_stereo_all
					la var stereo_diff "In-Out stereotyping index"
					
			* Generate humanization index
			
				* Generate inparty and outparty humanization indexes
		
					gen inparty_human = inparty_thought + inparty_sensations + inparty_love + inparty_anger
						la var inparty_human "Inparty humanization index"
		
					gen outparty_human = outparty_thought + outparty_sensations + outparty_love + outparty_anger
						la var outparty_human "Outparty humanization index"

				gen human_diff = inparty_human - outparty_human
					la var human_diff "In-Out humanization index"
					
						
			* Generate outparty empathy index
			
				alpha outparty_view_rec outparty_perspective, std item detail gen(idx_outgroup_empathy)
					la var idx_outgroup_empathy "Outgroup empathy index"
			
						
			* Generate support for civil discourse index
			
				alpha sup_cvl_grp sup_cvl_off, std item detail gen(idx_civil_support)
					la var idx_civil_support "Support for civil discourse index"	
					
			* Generate capacity for civil discourse index
			
				alpha cap_cvl_tlk cap_cvl_off, std item detail gen(idx_civil_capacity)
					la var idx_civil_capacity "Capacity for civil discourse index"
			
			* Generate moralization index
			
				alpha policy_imm_moral policy_health_moral policy_abort_moral policy_guns_moral policy_deficit_moral, std item detail gen(idx_moralization)
					la var idx_moralization "Moralization of politics index"
			
			* Generate outparty contact index
			
				alpha outparty_contact outparty_talk pricon_frnd_diff, std item detail gen(idx_outparty_contact)
					la var idx_outparty_contact "Outparty contact index"
		
		
			* Generate empathy index

				alpha empathy_twosides empathy_sorry_rec empathy_listen_rec empathy_feelings empathy_imagine, std item detail gen(idx_empathy)
					la var idx_empathy "General empathy index"	
				
			* Behavioral measure (donations)
			
				egen idx_donate_depol = std(donate_depol)
				replace idx_donate_depol=-1*(idx_donate_depol)
					la var idx_donate_depol "(Reversed) Donation to bridge the divide"
			
			* Behavioral measure (conversations)
			
				gen outparty_converse = (q195=="2") if q195!=""
					la var outparty_converse "Initiated conversation with out-partisan in last 5 days"
						
				gen outparty_no_converse = (q195=="1") if q195!=""
					la var outparty_no_converse "Did not initiate conversation with out-partisan in last 5 days"
						
			* Generate omnibus polarization index (with and without outparty conversations)
			
				pwcorr idx_affect_pol_noneg_comf dinparty idx_donate_depol
			
				alpha idx_affect_pol_noneg_comf dinparty idx_donate_depol, std item detail gen(idx_pol_omnibus)
					la var idx_pol_omnibus "Omnibus polarization index"
					
				pwcorr idx_affect_pol_noneg_comf dinparty idx_donate_depol outparty_no_converse
				
				alpha idx_affect_pol_noneg_comf dinparty idx_donate_depol outparty_no_converse, std item detail gen(idx_pol_omnibus_conv)
					la var idx_pol_omnibus_conv "Omnibus polarization index (incl. out-partisan conversations)"

						

			
			* Candidate experiment
			
				*VOTE/ABSTAIN SINGLE VARIABLE FOR ALL RESPONDENTS

			gen experiment_elect_all = .
				replace experiment_elect_all=0 if experiment_elect_one==2 /// 
					| experiment_elect_two==2 ///
					| experiment_elect_three==2 ///
					| experiment_elect_four==2 ///
					| experiment_elect_five==2 ///
					| experiment_elect_six==2 ///
					| experiment_elect_seven==2 ///
					| experiment_elect_eight==2
				replace experiment_elect_all=1 if experiment_elect_one==1 ///
					| experiment_elect_two==1 ///
					| experiment_elect_three==1 ///
					| experiment_elect_four==1 ///
					| experiment_elect_five==1 ///
					| experiment_elect_six==1 ///
					| experiment_elect_seven==1 ///
					| experiment_elect_eight==1
				la def experiment_elect_all 1 "Abstain" 0 "Vote"
				la val experiment_elect_all experiment_elect_all
				la var experiment_elect_all "Exp. elections all vote / abstain"
				
				*IN OR OUTPARTY PREFERENCE SINGLE VARIABLE FOR ALL RESPONDENTS
				
			gen experiment_pref_inout = .
				replace experiment_pref_inout=0 if demcan_t_one==1 ///
					| demcan_c_one==1 ///
					| repcan_t_one==1 ///
					| repcan_c_one==2 ///
					| demcan_t_two==1 ///
					| demcan_c_two==1 ///
					| repcan_t_two==2 ///
					| repcan_c_two==2 ///
					| demcan_t_three==1 ///
					| demcan_c_three==1 ///
					| repcan_t_three==2 ///
					| repcan_c_three==2 ///
					| demcan_t_four==1 ///
					| demcan_c_four==1 ///
					| repcan_t_four==2 ///
					| repcan_c_four==2 ///
					| demcan_t_five==1 ///
					| demcan_c_five==1 ///
					| repcan_t_five==2 ///
					| repcan_c_five==2 ///
					| demcan_t_six==1 ///
					| demcan_c_six==1 ///
					| repcan_t_six==2 ///
					| repcan_c_six==2 ///
					| demcan_t_seven==1 ///
					| demcan_c_seven==1 ///
					| repcan_t_seven==2 ///
					| repcan_c_seven==2 ///
					| demcan_t_eight==1 ///
					| demcan_c_eight==1 ///
					| repcan_t_eight==2 ///
					| repcan_c_eight==2 
				replace experiment_pref_inout=1 if demcan_t_one==5 ///
					| demcan_c_one==2 ///
					| repcan_t_one==5 ///
					| repcan_c_one==4 ///
					| demcan_t_two==2 ///
					| demcan_c_two==2 ///
					| repcan_t_two==4 ///
					| repcan_c_two==4 ///
					| demcan_t_three==2 ///
					| demcan_c_three==2 ///
					| repcan_t_three==5 ///
					| repcan_c_three==5 ///
					| demcan_t_four==2 ///
					| demcan_c_four==2 ///
					| repcan_t_four==5 ///
					| repcan_c_four==5 ///
					| demcan_t_five==2 ///
					| demcan_c_five==2 ///
					| repcan_t_five==5 ///
					| repcan_c_five==5 ///
					| demcan_t_six==2 ///
					| demcan_c_six==2 ///
					| repcan_t_six==5 ///
					| repcan_c_six==5 ///
					| demcan_t_seven==2 ///
					| demcan_c_seven==2 ///
					| repcan_t_seven==5 ///
					| repcan_c_seven==5 ///
					| demcan_t_eight==2 ///
					| demcan_c_eight==2 ///
					| repcan_t_eight==7 ///
					| repcan_c_eight==5 
				la def experiment_pref_inout 0 "Inparty candidate" 1 "Outparty candidate"
				la val experiment_pref_inout experiment_pref_inout
				la var experiment_pref_inout "Exp. elections all In / Out pref. "
				
				*CANDIDATE INPARTY/OUTPARTY PREFERENCE + VOTE/ABSTAIN SINGLE VARIABLE FOR ALL REPSONDENTS
			
			gen prodem_can_exp = .
				replace prodem_can_exp=0 if experiment_elect_all==0 & experiment_pref_inout==0 	
				replace prodem_can_exp=1 if experiment_elect_all==1 & experiment_pref_inout==0 
				replace prodem_can_exp=2 if experiment_elect_all==1 & experiment_pref_inout==. 
			   	replace prodem_can_exp=3 if experiment_elect_all==1 & experiment_pref_inout==1 
				replace prodem_can_exp=4 if experiment_elect_all==0 & experiment_pref_inout==1 	
				la def prodem_can_exp 0 "Pref INPARTY, would vote" 1 "Pref INPARTY, would abstain" 2 "Pref MISSING, would abstain" 3 "Pref OUTPARTY, would abstain" 4 "Pref OUTPARTY, would vote"
				la val prodem_can_exp prodem_can_exp
				la var prodem_can_exp "Candidate experiment PREF/VOTE ALL"
			
				*VOTE INPARTY DUMMY SINGLE VARIABLE FOR ALL RESPONDENTS
				
			gen canexp_vote_inparty = .
				replace canexp_vote_inparty=0 if prodem_can_exp==1 | prodem_can_exp==2 | prodem_can_exp==3 | prodem_can_exp==4
				replace canexp_vote_inparty=1 if prodem_can_exp==0
				la def canexp_vote_inparty 0 "No vote inparty" 1 "Vote inparty"
				la val canexp_vote_inparty canexp_vote_inparty
				la var canexp_vote_inparty "Inparty vote candidate experiment ALL"
				
				*PREFERENCE INPARTY DUMMY SINGLE VARIABLE FOR ALL RESPONDENTS
				
			gen canexp_pref_inparty = .
				replace canexp_pref_inparty=0 if prodem_can_exp==2 | prodem_can_exp==3 | prodem_can_exp==4 
				replace canexp_pref_inparty=1 if prodem_can_exp==0 | prodem_can_exp==1
				la def canexp_pref_inparty 0 "No pref inparty" 1 "Pref inparty"
				la val canexp_pref_inparty canexp_pref_inparty
				la var canexp_pref_inparty "Inparty pref candidate experiment ALL"
			
		
		
		*Generate ad hominem index
			
				gen adhom_red = covid_protest_r + blm_oppose_r + greendeal_gen_r + elect_delay_r + daca_heart_r 
					la var adhom_red "Ad hom against reds"
				
				gen adhom_blue = healthcare_liberty_d + mailin_threat_d + police_anarch_d + covid_lockdown_d + gunban_cons_d 
					la var adhom_blue "Ad hom against blues"
				
				gen adhom_diff = .
					replace adhom_diff = adhom_red - adhom_blue if incolor=="Red"
					replace adhom_diff = adhom_blue - adhom_red if incolor=="Blue"
					la var adhom_diff "In-Out Ad hom index"
		
		*Year in college
			 gen freshman=q233=="4"
			 gen sophomore=q233=="3"
			 gen junior=q233=="2"
			 gen senior=q233=="1"
			 
			 	 
			 
		
/* SAVE */
				
			placevar campus party inparty outparty sid, before(finished)
				
			gen END=.
			
			foreach x of varlist q32 - END {
				ren `x' e_`x'
			}
			
			drop e_END
			
			gen IDENTIFIERS=.
				la var IDENTIFIERS "=============================="
			
			gen RAW_VARS=.
				la var RAW_VARS "=============================="
			
			gen CLEAN_VARS=.
				la var CLEAN_VARS "=============================="

			gen CONSTRUCTED_VARS=.
				la var CONSTRUCTED_VARS "=============================="


			placevar IDENTIFIERS, before(campus)

			placevar RAW_VARS, before(e_q32)
			
			placevar CLEAN_VARS, before(e_talk_politics)
	
			placevar CONSTRUCTED_VARS, before(e_idx_pol_engage)
			
			sort sid
			drop if sid==.
			

			save "endline_clean_all.dta", replace
	

	
